package com.edu.study.base.rest;

import com.edu.study.base.stuAnswerResultSummary.domain.AnswerResult;
import com.edu.study.base.stuAnswerResultSummary.domain.AnswerResultSummaryEntity;
import com.edu.study.base.stuAnswerResultSummary.domain.StuAnswerResultSummary;
import com.edu.study.base.stuAnswerResultSummary.service.IStuAnswerResultSummaryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

@Api(tags = "答题结果提交")
@RestController
@RequestMapping("/api/answerResult/")
public class AppAnswerResultSummaryController extends BaseController {



    @Autowired
    private IStuAnswerResultSummaryService stuAnswerResultSummaryService;

    @ApiOperation("获取当前用户能力测试的次数")
    @GetMapping("getUserAblityTestCount")
    public AjaxResult getAblityTestCount(){
        int count = 0;
        Long userId = SecurityUtils.getUserId();
        StuAnswerResultSummary summary = new StuAnswerResultSummary();
        summary.setAppUserId(userId);
        summary.setType(2);
        summary.setDeleteFlag("0");
        List<StuAnswerResultSummary> stuAnswerResultSummaries = stuAnswerResultSummaryService.selectStuAnswerResultSummaryList(summary);
        if(stuAnswerResultSummaries != null && stuAnswerResultSummaries.size() > 0){
            count = stuAnswerResultSummaries.size();
        }
        return AjaxResult.success(count);
    }

    /**
     * 试卷提交
     * @param answerResult
     * @return
     */
    @ApiOperation("能力测试交卷")
    @PostMapping("batchSubmitResult")
    public AjaxResult batchSubmitResult(@ApiParam AnswerResult answerResult){
        return stuAnswerResultSummaryService.batchSubmitResult(answerResult);
    }

    @ApiOperation("写作提交")
    @PostMapping("submitWrite")
    public AjaxResult submitWrite(@ApiParam AnswerResultSummaryEntity entity){
        return stuAnswerResultSummaryService.submitWrite(entity);
    }







//    @PostMapping("/submitSingle")
//    public AjaxResult submitLibrary(@RequestBody AnswerResultSummaryEntity entity){
//
//        return stuAnswerResultSummaryService.submitSingle(entity);
//
//    }

}
